//
//  VRBackVideoCell.m
//  VRFirefighting
//
//  Created by Veer on 2018/8/26.
//  Copyright © 2018年 Veer. All rights reserved.
//

#import "VRBackVideoCell.h"

#import <EZOpenSDKFramework/EZDeviceRecordFile.h>
#import <EZOpenSDKFramework/EZCloudRecordFile.h>

#import "DDKit.h"


@interface VRBackVideoCell()

@property (nonatomic, weak) UIImageView *iconImgView;
@property (nonatomic, weak) UILabel *timeLabel;
@property (nonatomic, weak) UILabel *timeLabel1;
@property (nonatomic, strong) UIView *bottomLineView;

@end

@implementation VRBackVideoCell

+ (instancetype)cellWith:(UITableView *)tablevie
{
    static NSString *cellID = @"VRBackVideoCell";
    
    VRBackVideoCell *cell = [tablevie dequeueReusableCellWithIdentifier:cellID];
    
    if (nil == cell) {
        
        cell = [[VRBackVideoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.accessoryType = UITableViewCellAccessoryNone;
        // lieview
        [self setupSubView];
        
    }
    return self;
}


- (void)setupSubView
{
    
    UILabel *timeLabel = [[UILabel alloc] init];
    timeLabel.textColor = RGB(140, 140, 140);
    timeLabel.font = VRFont(14);
    [self.contentView addSubview:timeLabel];
    self.timeLabel = timeLabel;
    
    UILabel *timeLabel1 = [[UILabel alloc] init];
    timeLabel1.textColor = RGB(140, 140, 140);
    timeLabel1.font = VRFont(14);
    [self.contentView addSubview:timeLabel1];
    self.timeLabel1 = timeLabel1;
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:@"icon_play_back_listitem"];
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:imageView];
    self.iconImgView = imageView;
    
    UIView *bottomLineView = [[UIView alloc] init];
    bottomLineView.backgroundColor = RGB(228, 228, 228);
    [self.contentView addSubview:bottomLineView];
    self.bottomLineView = bottomLineView;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerY.mas_equalTo(self.contentView);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(40);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.iconImgView.mas_right).offset(10);
        make.right.mas_equalTo(-5);
        make.height.mas_equalTo(20);
        make.top.mas_equalTo(10);
    }];
    
    [self.timeLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.timeLabel);
        make.right.mas_equalTo(-5);
        make.height.mas_equalTo(20);
        make.bottom.mas_equalTo(-10);
    }];
    
    [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(-0);
        make.bottom.mas_equalTo(self.contentView);
        make.height.mas_equalTo(0.5);
    }];
}


#pragma mark - setter && getter
- (void)setCloudRecord:(EZCloudRecordFile *)cloudFile selected:(BOOL)selected
{
    if (![cloudFile isKindOfClass:[EZCloudRecordFile class]])
    {
        return;
    }
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy日MM月dd日 HH:mm:ss";
    self.timeLabel.text = [NSString stringWithFormat:@"开始时间：%@", [formatter stringFromDate:cloudFile.startTime]];
    self.timeLabel1.text = [NSString stringWithFormat:@"结束时间：%@", [formatter stringFromDate:cloudFile.stopTime]];
    
    UIColor *tintColor = [UIColor grayColor];
    if(selected)
        tintColor = [UIColor dd_hexStringToColor:@"0x1b9ee2"];
    self.timeLabel.textColor = tintColor;
    self.timeLabel1.textColor = tintColor;
}

- (void)setDeviceRecord:(EZCloudRecordFile *)deviceFile selected:(BOOL)selected
{
    self.imageView.image = nil;
    self.imageView.backgroundColor = [UIColor grayColor];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy日MM月dd日 HH:mm:ss";
    self.timeLabel.text = [NSString stringWithFormat:@"开始时间：%@", [formatter stringFromDate:deviceFile.startTime]];
    self.timeLabel1.text = [NSString stringWithFormat:@"结束时间：%@", [formatter stringFromDate:deviceFile.stopTime]];
    
    UIColor *tintColor = [UIColor grayColor];
    if(selected)
        tintColor = [UIColor dd_hexStringToColor:@"0x1b9ee2"];
    self.imageView.layer.borderColor = tintColor.CGColor;
    self.imageView.layer.borderWidth = 1.0f;
    self.timeLabel.textColor = tintColor;
    self.timeLabel1.textColor = tintColor;
}

@end
